package groep3.ssc.main;

import groep3.ssc.controllers.Bootstrap;
import groep3.ssc.skaterViews.DirectionView;
import groep3.ssc.skaterViews.LastRoundTimeView;
import groep3.ssc.skaterViews.RoundNumberView;
import groep3.ssc.skaterViews.SkaterViewTemplate;
import groep3.ssc.skaterViews.TargetDifferenceView;
import groep3.ssc.skaterViews.TotalDistanceView;
import groep3.ssc.skaterViews.TotalTimeView;

import java.util.ArrayList;

import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;

public class Main extends FragmentActivity
{

    public static ArrayList<SkaterViewTemplate> skaterViews;

    public static SkaterViewTemplate skaterView1;
    public static SkaterViewTemplate skaterView2;

    SkateAppPagerAdapter skateAppPagerAdapter;
    public static ViewPager viewPager;
    private WakeLock wakeLock;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        new Bootstrap(this);

        skaterViews = new ArrayList<SkaterViewTemplate>();
        skaterViews.add(new DirectionView(getApplicationContext()));
        skaterViews.add(new LastRoundTimeView(getApplicationContext()));
        skaterViews.add(new RoundNumberView(getApplicationContext()));
        skaterViews.add(new TargetDifferenceView(getApplicationContext()));
        skaterViews.add(new TotalDistanceView(getApplicationContext()));
        skaterViews.add(new TotalTimeView(getApplicationContext()));

        //Remove title bar
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        //Remove notification bar
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);

        wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "WakeLock Tag");

        setContentView(R.layout.main);

        skateAppPagerAdapter = new SkateAppPagerAdapter(getSupportFragmentManager());
        viewPager = (ViewPager) findViewById(R.id.pager);
        viewPager.setAdapter(skateAppPagerAdapter);

        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener()
        {
            @Override
            public void onPageSelected(int position)
            {
                final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(viewPager.getWindowToken(), 0);//hide keyboard
            }

            @Override
            public void onPageScrolled(int position, float offset, int offsetPixels)
            {
            }

            @Override
            public void onPageScrollStateChanged(int state)
            {
            }
        });
    }

    @Override
    protected void onResume()
    {
        super.onResume();
        wakeLock.acquire();
    }

    @Override
    protected void onPause()
    {
        super.onPause();
        wakeLock.release();
    }
}